<template>
  <div class="evaluate-score">
    <span
      v-for="item in totalScore"
      :key="item"
      @click="setScore(item)"
      @mouseenter="currentScore = item"
      @mouseleave="currentScore = modelValue"
      class="iconfont"
      :class="currentScore < item ? ['icon-xin'] : ['icon-xin2', 'active']"
    ></span>
    <span class="text">{{textMap[currentScore]}}</span>
  </div>
</template>

<script>
import { reactive, ref } from 'vue'
export default {
  name: 'EvaluateScore',
  props: {
    modelValue: {
      type: Number,
      default: 0
    }
  },
  setup (props, { emit }) {
    const totalScore = ref(5)
    const currentScore = ref(0)
    const textMap = reactive({
      1: '非常差',
      2: '差',
      3: '一般',
      4: '好',
      5: '非常好'
    })
    const setScore = (item) => {
      // emit('update:modelValue', item)
      emit('update:modelValue', item)
    }
    return { totalScore, textMap, currentScore, setScore }
  }
}
</script>

<style lang="less" scoped>
.evaluate-score {
  .iconfont {
    margin-right: 10px;
    vertical-align: middle;
    cursor: pointer;
    &.active {
      color: #ff9240;
    }
  }
  .text {
    vertical-align: middle;
  }
}
</style>
